<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打字动画</title>
    <link rel="stylesheet" href="../public.css">
    <style>
        @keyframes typing {
            from {
                width: 0
            }
        }

        @keyframes caret {
            50% {
                border-color: transparent;
            }
        }

        h1 {
            width: 7.7em;
            white-space: nowrap;
            overflow: hidden;
            font-family: monospace;
            border-right: 1px solid black;
            animation: typing 8s steps(15), caret 1s steps(1) infinite;
        }
    </style>
</head>

<body>
    <div class="content">
        <h1></h1>
        <div class="box">
            <h1>CSS is awesome!</h1>
        </div>
    </div>
    <script>
        $$('h1').forEach(function (h1) {
            var len = h1.textContent.length, s = h1.style;
            s.width = len + 'ch';
            s.animationTimingFunction = "steps(" + len + "),steps(1)";
        });
    </script>
</body>

</html>